<!DOCTYPE html>
<html lang="en">
<head>
    <title>用户授权</title>
    <%include("/WEB-INF/views/common/basejs.html"){}%>
    <link rel="stylesheet" href="${ctxPath!}/js/extend/transfer/cyType.css" media="all">
    <script src="${ctxPath!}/js/extend/transfer/PinyinMatch.js"></script>
    <script>
        //config的设置是全局的
        layui.config({
            base: '../js/extend/transfer/' //假设这是你存放拓展模块的根目录
        }).use(['transferTool','form','layer','jquery'],function ()
        {
            var transferTool = layui.transferTool,
            form=layui.form,
            layer=layui.layer,
            $=layui.jquery;
            //监听提交///保存或修改
            form.on('submit(submitForm)', function (data) {
                var selectedVal=transferTool.selectedData;//获取选择角色的ID值
                $.ajax({
                  url:basePath+'/user/grantRoleToUser',
                  type:'post',
                  data:{userId:'${userId!}',roleStr:selectedVal},
                  dataType:'json',
                  success:function(data){
                      window.parent.closeGrantPage();
                      if(data.code==0){
                          window.parent.layer.msg(data.msg,{icon: 1});
                      }else{
                          window.parent.layer.msg(data.msg,{icon: 2});
                      }

                  },
                  error:function(msg){
                      layer.msg("系统内部错误");
                  }
                })
                return false;
            });
            transferTool.init({
                elem: "#tranferDiv",
                seletedValue: "${userRoleStr!}",  //已选,变量逗号隔开
                url: basePath+'/role/getList',  //url获取数据
                name: 'province',  //form表单获取的结果值
                nodeName:'roleName',
                nodeValue:'id'
            });
        });
    </script>
</head>
<body>
    <div class="layui-container">
        <div class="layui-form">
            <div id="tranferDiv" cyType="transferTool" style="text-align:center"></div>
            <div class="layui-form-item layui-hide">
                <button id="form-submit" class="layui-btn" lay-submit lay-filter="submitForm">保存</button>
            </div>
        </div>
    </div>
</body>
</html>